﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace TreeBuilder
{
	public class NodeBindAction : UndoableAction
	{
		private readonly DottedCanvas _canvas;
		private readonly IBinder _binder;

		public NodeBindAction(DottedCanvas canvas, IBinder binder)
		{
			_canvas = canvas;
			_binder = binder;
		}

		public override void Execute()
		{
			_canvas.Children.Add((UIElement)_binder);

			_binder.From.Links.Add(_binder);
			_binder.To.Links.Add(_binder);

            _binder.RefreshPoints();
		}

		public override void Undo()
		{
			_binder.To.Links.Remove(_binder);
			_binder.From.Links.Remove(_binder);

			_canvas.Children.Remove((UIElement)_binder);
		}
	}
}
